﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SIPO.master" AutoEventWireup="true" CodeFile="rptVoucherlist.aspx.cs" Inherits="reports_Transaction_rptHistoryTransaction" %>

<asp:Content ID="Content1" ContentPlaceHolderID="body" Runat="Server">
    <link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>
    <script src="<%= ResolveUrl("~/scripts/helper.js") %>" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#btnCancel").button({ icons: { primary: "ui-icon-close"} });
            $("#btnSubmit").button({ icons: { primary: "ui-icon-circle-arrow-e"} });

            $("#btnCancel").click(function () {

                $("#<%= txtPeriodeAwal.ClientID %>").val('Periode Awal ');
                $("#<%= txtPeriodeAkhir.ClientID %>").val('Periode Akhir');


            });

            $("#btnPrint").click(function () {
                var formUrl = '<%= ResolveUrl("~/lists/Report/rptVoucherPrint.aspx") %>';

                var grid = $('#table');
                var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
                selText = [];
                $.each(selIds, function () {
                    selText.push(grid.jqGrid('getCell', this, 'BillingNo'));
                });
                if (selIds.length == 0) {
                    alert('Pilih data yang akan di cetak !');
                }
                else if (selIds.length > 1) {
                    alert('Pilih satu record untuk cetak voucher !');
                }
                else {
                    window.open(formUrl + "?id=" + selText);
                }
            });

            var date = new Date();
            var currentMonth = date.getMonth();
            var currentDate = date.getDate();
            var currentYear = date.getFullYear();

            $("#<%= txtPeriodeAwal.ClientID %>").val('01/01/' + currentYear);
            $("#<%= txtPeriodeAkhir.ClientID %>").val(currentDate + '/' + parseInt((currentMonth) + 1) + '/' + currentYear);


            //            $("#<%= txtPeriodeAwal.ClientID  %>").focus(function () {
            //                $("#<%= txtPeriodeAwal.ClientID %>").val('');
            //            });
            //            $("#<%= txtPeriodeAkhir.ClientID  %>").focus(function () {
            //                $("#<%= txtPeriodeAkhir.ClientID %>").val('');
            //            });
            $("#<%= txtPeriodeAwal.ClientID  %>").datepicker({ showWeek: true, showButtonPanel: true,
                changeMonth: true, changeYear: true, dateFormat: 'dd/mm/yy',
                numberOfMonths: 1,
                onSelect: function (selected) {
                    $("#<%= txtPeriodeAkhir.ClientID %>").datepicker("option", "minDate", selected)
                    //  $("#<%= txtPeriodeAkhir.ClientID %>").val('Periode Akhir ');
                    if ($("#<%= txtPeriodeAkhir.ClientID  %>").val().toString().toLowerCase().indexOf('2') < 0) {
                        $("#<%= txtPeriodeAkhir.ClientID %>").val('Periode Akhir ');
                       // alert($("#<%= txtPeriodeAkhir.ClientID  %>").val().toString().toLowerCase());
                    }
                }
            });

            $("#<%= txtPeriodeAkhir.ClientID  %>").datepicker({ showWeek: true, showButtonPanel: true,
                changeMonth: true, changeYear: true, dateFormat: 'dd/mm/yy',
                numberOfMonths: 1,
                onSelect: function (selected) {
                    $("#<%= txtPeriodeAwal.ClientID %>").datepicker("option", "maxDate", selected)
                }
            });

            var IsLoad = true;


            var handleUrl = 'nothing'; //agar saat load data tidak muncul
            $('#table').jqGrid({
                url: handleUrl,
                datatype: 'json',
                colNames: ['NoTrans', 'Tanggal Transaksi', 'Nama Debitur', 'Jenis Transaksi'],
                colModel: [
                { name: 'BillingNo', hidden: true, index: 'INVOICEDATE', align: 'center', searchoptions: { sopt: ['eq', 'cn'] }, width: 200 },
           		{ name: 'BillingDate', index: 'BILLINGDATE', align: 'center', width: 115, formatter: 'date', formatoptions: { newformat: 'd M Y'} },
           		{ name: 'recDebtor.DebtorName', index: 'debtorname', align: 'center', width: 200 },
                { name: 'recTransactionType.TransTypeName', index: 'TRANSTYPENAME', align: 'center', width: 140 }
                //                { name: 'recBilling.ForPayment', index: 'FORPAYMENT', align: 'left', searchoptions: { sopt: ['eq', 'cn'] }, width: 400 },
                //                { name: 'recBilling.PaymentValue', index: 'VALUE', align: 'right', searchoptions: { sopt: ['eq', 'cn'] }, width: 200, formatter: 'currency', formatoptions: { decimalSeparator: ".", thousandsSeparator: ",", decimalPlaces: 2} },
                //                { name: 'PaymentValue', index: 'PAYMENTVALUE', align: 'right', searchoptions: { sopt: ['eq', 'cn'] }, width: 200, formatter: 'currency', formatoptions: { decimalSeparator: ".", thousandsSeparator: ",", decimalPlaces: 2} },
                         	],
                rowNum: 10,
                id: 'BillingNo',
                multiselect: true,
                rowList: [5, 10, 15, 20],
                pager: '#pager',
                sortname: 'recBilling.BillingDate',
                sortorder: "asc",
                viewrecords: true,
                jsonReader: { repeatitems: false },
                width: 750,
                height: '100%',
                caption: 'Laporan Voucher',
                ajaxGridOptions: { cache: false },
                ondblClickRow: function () {
                    //                OpenForm('edit');
                }
            });




            //            $("#btnPrint").click(function () {


            //                if (jQuery("#table").jqGrid('getGridParam', 'records') > 0) {
            //                    if (ok == true && tgl == true) {
            //                        var formUrl = '<%= ResolveUrl("~/reports/Transaction/rptHistoryTransactionViewer.aspx") %>';
            //                        var periodeawal = $("#<%= txtPeriodeAwal.ClientID %>").val();
            //                        var periodeakhir = $("#<%= txtPeriodeAkhir.ClientID %>").val();
            //                        if (periodeawal.toString().toLowerCase().indexOf('awal') > -1 && periodeakhir.toString().toLowerCase().indexOf('akhir') > -1 && tgl == true) {
            //                            window.open(formUrl + "?periodeAwal=&periodeAkhir=");
            //                        }
            //                        else {
            //                            if (periodeawal.toString() != "" && periodeakhir.toString() != "") {
            //                                window.open(formUrl + "?periodeAwal=" + periodeawal + "&periodeAkhir=" + periodeakhir);
            //                            }
            //                            else {
            //                                alert('Periode tanggal tidak valid !')
            //                            }
            //                        }
            //                    }
            //                    else {
            //                        alert("Tekan submit terlebih dahulu !");
            //                    }
            //                }
            //                else {
            //                    alert("Data kosong tidak dapat di cetak !");
            //                }
            //            });

            $("#btnSubmit").click(function () {

                var periodeawal = $("#<%= txtPeriodeAwal.ClientID %>").val();
                var periodeakhir = $("#<%= txtPeriodeAkhir.ClientID %>").val();

                if (periodeawal.toString().toLowerCase().indexOf('awal') < 0 && periodeakhir.toString().toLowerCase().indexOf('akhir') < 0) {

                    jQuery("#table").setGridParam({ url: '<%= ResolveUrl("~/AjaxHandler/Transaction/recBillinghandler.ashx") %>' + '?method=getdatavoucherreport&periodeawal=' + periodeawal + '&periodeakhir=' + periodeakhir + '&Jentrans=' });
                    jQuery("#table").trigger("reloadGrid", [{ page: 1}]);

                }

                else {
                    if (periodeawal.toString().toLowerCase().indexOf('2') < 0 && periodeakhir.toString().toLowerCase().indexOf('2') < 0) {

                        jQuery("#table").setGridParam({ url: '<%= ResolveUrl("~/AjaxHandler/Transaction/recBillinghandler.ashx") %>' + '?method=getdatavoucherreport&periodeawal=&periodeakhir=&Jentrans=' });
                        jQuery("#table").trigger("reloadGrid", [{ page: 1}]);
                    }
                    else {
                        $("#<%= txtPeriodeAwal.ClientID %>").val('Periode Awal ');
                        $("#<%= txtPeriodeAkhir.ClientID %>").val('Periode Akhir');

                        alert("Periode  tanggal tidak valid !");
                    }
                }
            });

        });
    </script>
<table border="0">
<tr>
            <td style="width: 96px; text-align: left; height: 38px;">
           
                        Periode
                    </td>
            <td style="height: 38px; width: 15px;">
                        :
                    </td>
            <td align="left" style="height: 38px">
                <asp:TextBox ID="txtPeriodeAwal" runat="server" Width="150"></asp:TextBox>
                s/d
                        <asp:TextBox ID="txtPeriodeAkhir" runat="server" Width="150"></asp:TextBox>
                <br />
            </td>

        </tr>
<%--<tr>
            <td style="width: 96px; text-align: left; height: 33px;">
           
                        Jenis Transaksi</td>
            <td style="height: 33px; width: 15px;">
                        :</td>
            <td align="left">
                <asp:DropDownList ID="ddlJenisPungutan" runat="server" Height="22px" Width="174px">
                </asp:DropDownList>
            </td>

        </tr>--%>
        </table>
        <br />
     <button class="dialog_link ui-state-default ui-corner-all" id="btnSubmit" type="button">
                        Lanjut
                    </button>   
                     <button class="dialog_link ui-state-default ui-corner-all" id="btnCancel" type="button">
                        Batal
                    </button>
    <br />
    <br />
    <table id="table" class="scroll" cellpadding="0" cellspacing="0""  >
    
    </table>
    <div id="pager" class="scroll">
    </div>
    <br />
    <div id="dialog" title="Default dialog">
    </div>
    
     <button class="dialog_link ui-state-default ui-corner-all" id="btnPrint" type="button">
                        Cetak
                    </button>
   
</asp:Content>

